package com.ss.android.article.base.feature.app.b;

import android.os.Looper;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.app.AppData;

public final class e {
    private static int a;
    private static long b;

    static {
        e.a = 0;
        e.b = 0;
    }

    public static void shrinkCache(DBHelper arg4) {
        while (!AppData.getInstance().isAppForeground) {
            if (!arg4.isSQLiteDatabaseAvailable()) {
                return;
            }

            if ((Logger.debug()) && Looper.myLooper() == Looper.getMainLooper()) {
                throw new IllegalThreadStateException("DB operation cannot be run in UI thread.");
            }

            if (System.currentTimeMillis() - e.b <= 900000) {
                return;
            }

            switch (e.a) {
                case 0: {
                    Logger.d("DBShrinkHelper", "Background shrinkArticleCache");
                    arg4.cleanV30Article();
                    break;
                }
                case 1: {
                    Logger.d("DBShrinkHelper", "Background shrinkCategoryCache");
                    arg4.cleanCategory();
                    break;
                }
                case 2: {
                    Logger.d("DBShrinkHelper", "Background shrinkEssayCache");
                    arg4.cleanV30Essay();
                    break;
                }
                case 3: {
                    Logger.d("DBShrinkHelper", "Background shrinkSearchCache");
                    arg4.cleanSearchWord();
                    break;
                }
                case 4: {
                    Logger.d("DBShrinkHelper", "Background shrinkCategoryMetaLocalCache");
                    arg4.shrinkCategoryMeta(System.currentTimeMillis());
                    e.b = System.currentTimeMillis();
                    break;
                }
            }
            int v0 = e.a + 1;
            e.a = v0;
            e.a = v0 % 5;
        }
    }
}

